<include file="public@header"/>
<style>
    .data-info-container{
        display: flex;
    }
    .data-info-container-left{
        flex: 1;
    }
    .data-info-container-right{
        flex: 2;
        margin-left: 20px;
    }
</style>
</head>
<body>
<div class="wrap">
    <div class="data-info-container">
        <div class="data-info-container-left">
            <div class="panel panel-danger">
                <div class="panel-heading">
                    <h3 class="panel-title">本年接口访问次数</h3>
                </div>
                <div class="panel-body">
                    {$year}
                </div>
            </div>
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">本月接口访问次数</h3>
                </div>
                <div class="panel-body">
                    {$month}
                </div>
            </div>
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title">本周接口访问次数</h3>
                </div>
                <div class="panel-body">
                    {$week}
                </div>
            </div>
            <div class="panel panel-warning">
                <div class="panel-heading">
                    <h3 class="panel-title">本日接口访问次数</h3>
                </div>
                <div class="panel-body">
                    {$day}
                </div>
            </div>
        </div>
        <div class="data-info-container-right">
            <div id="main" style="height:400px;"></div>
        </div>
    </div>
</div>
<script src="__STATIC__/js/admin.js?v={$_static_version}"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url:"{:url('Main/getChartData')}",
            type:"GET",
            success:function (res) {
                drawChart(res.data.time,res.data.total)
            },
            error:function () {
                alert('获取图表信息失败')
            }
        })
    })

    function drawChart(x,y){
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
            title:{
                text:'近七天API请求次数'
            },
            tooltip: {
                show: true,
                trigger: 'axis'
            },
            xAxis: {
                type: 'category',
                data: x
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: y,
                    type: 'line'
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
</script>
</body>
</html>
